package com.example.demo.services.impl;

import com.example.demo.domain.Category;
import com.example.demo.domain.Item;
import com.example.demo.domain.Product;
import com.example.demo.persistence.CategoryDao;
import com.example.demo.persistence.ItemDao;
import com.example.demo.persistence.ProductDao;
import com.example.demo.services.CatalogService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@MapperScan("com.example.demo.persistence")
@Service("catalogService")
public class CatelogServiceImpl implements CatalogService {
    @Autowired
    private CategoryDao categoryDao;

    @Autowired
    private ProductDao productDao;

    @Autowired
    private ItemDao itemDao;


    @Override
    public List<Category> getCategoryList(){
        return categoryDao.getCategoryList();
    }

    @Override
    public Category getCategory(String categoryId){
        return categoryDao.getCategory(categoryId);
    }

    @Override
    public List<Product> getProductList() {
        return productDao.getProductList();
    }

    @Override
    public Product getProduct(String productId){
        return productDao.getProduct(productId);
    }

    @Override
    public List<Product> getProductListByCategory(String categoryId){
        return productDao.getProductListByCategory(categoryId);
    }

    @Override
    public List<Product> searchProductList(String keyword){
        return productDao.searchProductList("%"+keyword.toLowerCase()+"%");
    }

    @Override
    public List<Item> getItemListByProduct(String productId){
        return itemDao.getItemListByProduct(productId);
    }

    @Override
    public Item getItem(String itemId){
        return itemDao.getItem(itemId);
    }

    @Override
    public boolean isItemInStock(String itemId){
        return itemDao.getInventoryQuantity(itemId) > 0;
    }
}
